import logging.handlers
import os

BASE_PATH =os.path.dirname(__file__)


def init_log_config():
    logger = logging.getLogger()
    logger.setLevel("INFO")
    sh = logging.StreamHandler()
    filename = BASE_PATH + "/log/XiaoShuoWang.log"
    fh = logging.handlers.TimedRotatingFileHandler(filename,
           "midnight",1,7,encoding="utf-8")
    fmt = ("%(asctime)s %(levelname)s [%(name)s] "
           "[%(filename)s (%(funcName)s:%(lineno)d] - %(message)s")#设置日志格式
    formatter = logging.Formatter(fmt) # 创建格式化器
    sh.setFormatter(formatter)  # 流处理器设置格式化器
    fh.setFormatter(formatter)  # 文件处理器设置格式化器
    logger.addHandler(sh)  # 日志器添加流处理器
    logger.addHandler(fh)  # 日志器添加文件处理器
